import type {MockMethod} from "vite-plugin-mock";
import success from "../success.json"
import {findDetailFromList, findItemById, getUrlPath} from "../utils";
import list1 from "./xzqlist.json";
import list2 from "./xzqlist2.json"
import tree1 from "./tree1.json"
import tree2 from "./tree2.json"
import tree3 from "./tree3.json"
import xzqchangelist from "./xzqchangelist.json";
import areatree from "./area-tree.json"
import areatree2 from "./area-tree2.json"

const xzqs = [
    {
        url: "/xzq/list",
        method: "post",
        response: ({body, query}: any) => {
            if (body.page == 1) {
                return list1;
            } else {
                return list2;
            }
        }
    },
    {
        url: "/xzq/xzqtree",
        method: "get",
        response: ({query}: any) => {
            if (query.parentcode == "0") {
                return tree1;
            } else if (query.parentcode.length == 2) {
                return tree2;
            } else if (query.parentcode.length == 4) {
                return tree3;
            }
            return success;
        }
    },
    {
        url: "/xzq/detailById/:id",
        method: "get",
        response: (body: any) => {
            let id = getUrlPath("/xzq/detailById/:id", body.url, "id");
            console.log(id);
            return findDetailFromList(list1.data.list, id, "xzqId");
        }
    },
    {
        url: "/xzq/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/xzq/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    }
]

const xzqChanges = [
    {
        url: "/xzq/change/list",
        method: "post",
        response: ({body, query}: any) => {
            return xzqchangelist;
        }
    },
    {
        url: "/xzq/change/detail/:id",
        method: "get",
        response: (body: any) => {
            let id = getUrlPath("/xzq/change/detail/:id", body.url, "id");
            console.log(id);
            return findDetailFromList(xzqchangelist.data.list, id, "changeId");
        }
    },
    {
        url: "/xzq/change/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/xzq/change/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    }
]


const areas = [{
    url: "/xzq/area/areaXzqtree",
    method: "get",
    response: ({body, query}: any) => {
        if (query.parentId == "0") {
            return areatree;
        } else {
            return areatree2;
        }
    }
},
    {
        url: "/xzq/area/area-save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/xzq/area/area-delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    },
    {
        url: "/xzq/area/xzqs/:id",
        method: "get",
        response: () => {
            return tree1;
        }
    }
]


export default [...xzqs, ...xzqChanges, ...areas] as MockMethod[];
